﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

using AKMII.DMRA.Common;
using AKMII.DMRA.DataAccess;
using AKMII.DMRA.Business.Rule;

namespace AKMII.DMRA.Business.Management
{
    public class PowerManager
    {
        public PowerAccesor accessor;

        public PowerManager()
        {
            accessor = new PowerAccesor();
        }

        public List<PowerName> GetPowerNameList(string assignmentName, List<string> zipCodes)
        {
            List<PowerName> powerNames = new List<PowerName>();

            try
            {
                if (zipCodes != null && zipCodes.Count > 0)
                {
                    int number = 50 / zipCodes.Count;

                    foreach (var zipCode in zipCodes)
                    {
                        List<PowerName> powerNamesPerZip = accessor.GetPowerNameList(assignmentName, zipCode, number);
                        powerNames.AddRange(powerNamesPerZip);
                    }
                }
                else
                {
                    powerNames = accessor.GetPowerNameList(assignmentName, null, 50);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occurs in get powerNames", ex);
            }

            return powerNames.Take(50).ToList<PowerName>();
        }

        /*
        public List<PowerName> GetPowerNameList(string assignmentName, List<string> cities)
        {
            List<PowerName> powerNames = new List<PowerName>();

            try
            {
                if (cities != null && cities.Count > 0)
                {
                    int number = 50 / cities.Count;

                    foreach (var city in cities)
                    {
                        List<PowerName> powerNamesPerCity = accessor.GetPowerNameList(assignmentName, city, number);
                        powerNames.AddRange(powerNamesPerCity);
                    }

                    if (powerNames.Count < 50)
                    {
                        List<PowerName> randomPowerNames = accessor.GetPowerNameList(assignmentName, null, 50);
                        powerNames.AddRange(randomPowerNames);
                    }
                }
                else
                {
                    powerNames = accessor.GetPowerNameList(assignmentName, null, 50);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occurs in get powerNames", ex);
            }

            return powerNames.Take(50).ToList<PowerName>();
        }*/
    }
}
